﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenCvSharp;
using OpenCvSharp.Blob;

namespace RecognitionNumbers
{
    public class Recognition : Filter
    {
        char c;
        public Recognition(IplImage image)
        {
            
            original = image.Clone();
            Symbol s = new Symbol();
            int[] sr = new int[s.lS.Length];
            CvSize size = new CvSize(20, 20);
            IplImage t = new IplImage(size, original.Depth, original.NChannels);
            Cv.Resize(original, t, Interpolation.Linear);
            Gray gray = new Gray(t);
            Binarization bw = new Binarization(gray.output, 125);
            int max = 0;
            for (int i = 0; i < s.lS.Length-1; i++)
            {
                int temp=0;
                for (int i1 = 0; i1 < bw.output.Width-1; i1++)
                    for (int j1 = 0; j1 < bw.output.Height-1; j1++)
                        if (bw.output[i1, j1].Val0 != s.lS[i][i1, j1].Val0) 
                            temp++;
                sr[i] = temp;
                if (temp < sr[max]) max = i;
            }
            c =s.lN[max];
        }

        public char symbol
        {
            get
            {
                return c;
            }
           
        }
    }
}
